import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// 全局配置
import localStorage from "./utilsCustomize/localStorage";
import dateTime from "./utilsCustomize/dateTime";
import http from './config/http.js';
import './assets/scss/reset.scss';

// 第三方
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.prototype.$localStorage = localStorage;
Vue.prototype.$dateTime = dateTime;
Vue.prototype.$http = http;

Vue.use(ElementUI);

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {

  let accessLogin = localStorage.get('accessLogin');

  store.commit('clickMenuMutations', to.name);

  if (!accessLogin && to.name !== 'Login') {

    ElementUI.Message({
      showClose: true,
      message: '登录信息已过期，请重新登录',
      type: 'error'
    });

    next({ name: 'Login' });
  } else {
    next();
  }

});

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    store.commit('menuListMutations');
  }
}).$mount("#app");
